<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        .content{
            margin:200px auto;
            width:200px;
            height:200px;  
            background: #db473c;  
            color:#fff;   
        }
        .container {
            transform-style: preserve-3d;
            perspective: 500px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="content"></div>
    </div>
    <script type="text/javascript">
        (function(){
            var content=document.querySelector(".content")
                content.onmousemove=function(e){
                    var evt=e||window.event;
                    var rotateY=-(content.clientWidth/2-evt.offsetX)/10;//e.offsetX相对于事件触发对象左上角水平距离
                    var rotateX=(content.clientHeight/2-evt.offsetY)/10;
                    content.style.transform=`rotateX(${rotateX}deg) rotateY(${rotateY}deg)`
                }
        }
        )()
    </script>
</body>
</html>